﻿#ifndef TESTALGORITHMONE_H
#define TESTALGORITHMONE_H

#include <stdio.h>
#define STEP_Befor 'A'

void testAlgorithm()
{
    char *str1 = "lsiugawvodglmvosdPJO";
    char *str2 = "AaBbCcsdourOJIOjos";
    char *pStr1 = str1;
    char *pStr2 = str2;

    int nArrayCount = 'z' - 'A' + 1;
    int arrayCount['z' - 'A' + 1] = {0};

    // 先遍历str1,按照ASCII码,计算各字符在新数组中的下标
    while ('\0' != *pStr1)
    {
        if(('A' <= *pStr1) && (*pStr1 <= 'z'))
        {
            int nArrayIndex = *pStr1 - STEP_Befor;

            if(-1 < nArrayIndex && nArrayIndex < nArrayCount)
            {
                arrayCount[nArrayIndex]++;
            }
        }

        pStr1++;
    }

    // 遍历str2,按照ASCII码,计算各字符在新数组中的下标
    while ('\0' != *pStr2)
    {
        if(('A' <= *pStr2) && (*pStr2 <= 'z'))
        {
            int nArrayIndex = *pStr2 - STEP_Befor;
            if(-1 < nArrayIndex && nArrayIndex < nArrayCount)
            {
                arrayCount[nArrayIndex]++;
            }
        }

        pStr2++;
    }

    for(int nIdx = 0; nIdx < nArrayCount; nIdx++)
    {
        if(0 == arrayCount[nIdx])
        {
            continue;
        }
        // 统计各字母出现的次数
        //printf("befor : %c : %d\n",nIdx+STEP_Befor, arrayCount[nIdx]);

        // 按字母顺序输出合并后的字符串
        int nShowCount = arrayCount[nIdx];
        while(0 != nShowCount)
        {
            printf("%c",nIdx+STEP_Befor);
            nShowCount--;
        }
    }
}


#endif // TESTALGORITHMONE_H
